// pages/chat/index.js
const app = getApp()
var appid = app.globalData.appid;

Page({
    data: {
        inputValue: '',
        article_id: '1'
    },
    onLoad: function (options) {
        var that = this

        wx.getSetting({
            success: (res) => {
                if (res.authSetting["scope.userInfo"]) {
                    that.setData({
                        show_aur_button: false
                    })
                }
            }
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        //console.log(that.data);
        return {
            title: app.globalData.shareData.share,
            imageUrl: app.globalData.shareData.thumb,
            path: 'pages/invitation/index',
            success: function (res) {
                wx.showToast({
                    title: '分享成功',
                })
            },
            fail: function (res) {
                // 转发失败
                wx.showToast({
                    title: '分享取消',
                })
            }
        }
    },
    bindKeyInput: function (e) {
        this.setData({
            inputValue: e.detail.value
        })
    },
    foo: function () {
        var that = this;
        if (that.data.inputValue) {
            //留言内容不是空值
            let userInfo = that.data.userInfo;
            let name = userInfo.nickName;
            let face = userInfo.avatarUrl;
            let words = that.data.inputValue;
            wx.request({
                url: "",
                data: {
                    'c': 'send',
                    'appid': appid,
                    'nickname': name,
                    'face': face,
                    'words': words
                },
                method: "GET",
                dataType: "json",
                success: res => {
                    // console.log(res.data);
                    if (res.data.success) {
                        that.setData({
                            chatList: res.data.chatList,
                            chatNum: res.data.chatNum
                        });
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            showCancel: false
                        })
                    } else {
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            showCancel: false
                        })
                    }
                }
            })
        }
        that.setData({
            inputValue: ''//将data的inputValue清空
        });
        return;
    }
})
